﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="false"
    CodeFile="recImpositionAlllist.aspx.cs" Inherits="SIPO.Web.Lists.Administration.Catalog.recImpositionAlllist" %>

<asp:Content ID="ctnBody" ContentPlaceHolderID="body" runat="server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
    <script src="<%= ResolveUrl("~/scripts/helper.js") %>" type="text/javascript"></script>
    <div style="display: none">
        <button id="btnReview" type="button" onclick="OpenForm('historikoreksi');">
            Histori Koreksi</button>
    </div>
    <br />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <br />
    <div id="dialog" title="Default dialog">
    </div>
    <script type="text/javascript">
        $("#btnReview").button({ icons: { primary: "ui-icon-pencil"} });

    </script>
    <script type="text/javascript">

        var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Transaction/recImpositionhandler.ashx") %>';

        $('#table').jqGrid({
            url: handlerUrl + '?method=getdata',
            datatype: 'json',
            colNames: ['ID', 'Sub Sub Sector', 'Nama Perusahaan', 'Dasar Pengenaan', 'Tahun Laporan Keuangan', 'Nilai Pengenaan OJK (Rp)', 'Nilai Pengenaan Debitur (Rp)', 'Kewajiban (Rp)', 'Download', 'Histori Koreksi'],
            colModel: [
                    { name: 'ImpositionID', hidden: true, index: 'ImpositionID', width: 5 },
                    { name: 'recSubSubSector.SubSubSectorName', index: 'SubSubSectorName', width: 300 },
                    { name: 'recDebtor.DebtorName', index: 'DebtorName', width: 200 },
                    { name: 'recImpositionBase.ImpositonBaseName', index: 'ImpositonBaseName', width: 100 },
                    { name: 'YearReport', index: 'YearReport', width: 130 },
                    { name: 'OJKValue', index: 'recImposition.OJKValue', width: 150, formatter: 'currency', formatoptions: { prefix: '', suffix: '', thousandsSeparator: ',' }, align: 'right' },
                    { name: 'DebtorValue', index: 'recImposition.DebtorValue', width: 170, formatter: 'currency', formatoptions: { prefix: '', suffix: '', thousandsSeparator: ',' }, align: 'right' },
                    { name: 'TariffValue', index: 'TariffValue', width: 100, formatter: 'currency', formatoptions: { prefix: '', suffix: '', thousandsSeparator: ',' }, align: 'right' },
                    { name: 'ImpositionID', index: 'ImpositionID', align: 'center', formatter: returnMyLink, width: 100 },
                    { name: 'HistoriKoreksi', index: 'HistoriKoreksi', align: 'center', search: false, sortable: false, width: 100 }

           	],
            rowNum: 10,
            id: 'ImpositionID',
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'recImposition.ImpositionID',
            sortorder: "asc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            width: 1300,
            height: '100%',
            caption: 'Dasar Pengenaan Iuran Berkala',
            ajaxGridOptions: { cache: false },
            gridComplete: function () {
                var ids = $('#table').jqGrid('getDataIDs');
                for (var i = 0; i < ids.length; i++) {
                    var _impositionID = $('#table').jqGrid('getCell', ids[i], 'ImpositionID');
                    var _subsubsector = $('#table').jqGrid('getCell', ids[i], 'recSubSubSector.SubSubSectorName');
                    var _debtorname = $('#table').jqGrid('getCell', ids[i], 'recDebtor.DebtorName');
                    idHistoriKoreksi = "<a href='javascript:void(0);' class='dialog_link ui-corner-all' title='Histori Koreksi' onclick=\"onclickButtonHistoriKoreksi('" + _impositionID + "', '" + _subsubsector + "','" + _debtorname + " ');\"><span class='ui-icon ui-icon-newwin'></span>...</a>";

                    $('#table').jqGrid('setRowData', ids[i], { HistoriKoreksi: idHistoriKoreksi });
                }
            }
        });

        $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Refresh' },
        {}, {}, {}, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true });
        hidecoloumn();

        function onclickButtonHistoriKoreksi(impositionID, subsubsector, debtorname) {
            $('#table').jqGrid('resetSelection');

            var urlList = '<%= ResolveUrl("~/lists/transaction/recImpositionHistorylist.aspx") %>';
            $('#dialog').load(urlList + '?' + 'method=getdata&ImpositionID=' + impositionID + '&menuId=' + '<%= base.MenuID %>').dialog({ autoOpen: false, modal: false, width: 680, height: 300, title: 'Histori Koreksi untuk Sub Sub Sector ' + subsubsector +' - ' + debtorname });
            $('#dialog').dialog('open');
        }

        function downloadfile(cellValue) {
            var objrecImposition = new Object();
            objrecImposition.ImpositionID = encodeURIComponent(cellValue);
            jsonData = JSON.stringify(objrecImposition);
            var handlerUrl = '<%= ResolveUrl("~/ajaxhandler/loaddata/downloadhandler.ashx") %>';
            $.ajax({
                type: 'POST',
                url: handlerUrl + "?method=checkfileDasarPengenaan",
                contentType: 'application/json',
                dataType: 'json',
                data: jsonData,
                success: function (data) {
                    if (data.IsSuccess) {
                        window.open(handlerUrl + '?method=downloadDasarPengenaan&impositionId=' + cellValue, 'popUpWindow', 'height=400,width=800,left=300,top=200,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=yes');
                        //return "<a target='_blank' href='" + handlerUrl + "method=download&sanction_id=" + cellValue + "' >download</a>";
                    }
                    else {
                        alert(data.Message);
                    }
                },
                error: function (response) {
                    //var r = JSON.parse(response.responseText);
                    alert("Error Check File Download"); //Message: " + r.Message);
                }
            });

        }

        function returnMyLink(cellValue, options, rowdata) {
            var handleurlDownload = '<%= ResolveUrl("~/ajaxhandler/loaddata/downloadhandler.ashx?method=downloadDasarPengenaan") %>';
            //return "<a target='_blank' href='" + handleurlDownload + "&sanction_id=" + cellValue + "' >download</a>";
            return "<a  href='#' onclick='downloadfile(" + cellValue + ")' >download</a>";
        }

        function hidecoloumn() {
            var userTypeId = "<%= base.UserTypeID %>";
            if (userTypeId == 1 || userTypeId == 2) {
                $("#table").jqGrid('hideCol', ["recDebtor.DebtorName"]);
            }
        }

        function OpenForm(ctl) {

            var formUrl = '<%= ResolveUrl("~/forms/transaction/recImpositionform.aspx") %>';

            var grid = $('#table');
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
            $.each(selIds, function () {
                selText.push(grid.jqGrid('getCell', this, 'ImpositionID'));
            });

            if (ctl == 'historikoreksi') {

                if (selIds.length == 0) {
                }
                else if (selIds.length > 1) {
                    alert('Pilih satu record untuk ubah data.');
                }
                else {
                    $('#dialog').load(formUrl + '?id=' + selText + '&menuid=' + '<%= base.MenuID %>').dialog({ autoOpen: false, modal: true, width: 600, title: 'Ubah Dasar Pengenaan' });
                    $("#dialog").dialog('open');
                }
            }
        }
    
    </script>
</asp:Content>
